#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QChar>//图标
#include <QChartView>//图标视图
#include <QValueAxis>
#include <QSplineSeries>//曲线
//#include <QLineSeries>//折线
#include <QSerialPort>
#include <QSerialPortInfo>
#include <QThread>

QT_CHARTS_USE_NAMESPACE//QChart宏声明
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();



private slots:
    void on_open_btn_clicked();
    void receiveInfo();
    void on_hv_btn_clicked();

    void on_single_btn_clicked();

    void on_save_btn_clicked();

    void on_show_btn_clicked();

    void on_auto_btn_clicked();

    void on_syns_btn_clicked();

private:
    Ui::Widget *ui;

    /*-------------variable----------------*/
    // 图表
    QSplineSeries *splineSeries;//曲线
    QChart *chart;//创建图表
    QValueAxis *valueAxisX;
    QValueAxis *valueAxisY;

    // 串口相关
    QSerialPort global_port;
    bool receivedFlag = false;
    bool OpenorClose_Flag = false;
    bool stop_flag = true;
    bool freq_flag = true;
    bool receivingData=false;



    //接收数据
    QVector<double> x_val,y_val,count_x,count_y;
    QVector<double> save_x,save_y;
    QVector<double> v_val;
    int count=0;
    int freq,save_freq;
    float Vpp,save_Vpp;
    double max_val;
    struct Typedef_osc {
        float max_value;
        float min_value;
        int max_index;
        int min_index;
    };
    Typedef_osc osc_data;

    /*-------------function----------------*/
    void system_init();
    QStringList getPortNameList();
    void creat_graph(void);//在QCustomplot创建曲线
    void creat_sin_osc(void);//正弦波创建
    Typedef_osc findExtremum(const QVector<double> &floatArray);//冒泡排序
    Typedef_osc quickSort(QVector<double> &arr, int left, int right);//快速排序
};



#endif // WIDGET_H
